{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from entity import Card, Player\n",
    "from utils import SettlementCalculator"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "# 测试示例\n",
    "# 构造一个玩家和结算器\n",
    "player = Player(name=\"测试玩家\")\n",
    "calc = SettlementCalculator()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "结算【杀】第一次使用，得分：0\n"
     ]
    }
   ],
   "source": [
    "# 构造几张测试卡牌\n",
    "# 示例1：使用一张正常【杀】牌（第一次使用）\n",
    "card1 = Card(1, \"杀\", \"♦️\", \"6\", \"基本牌\")\n",
    "score1 = calc.settle(card1, player)\n",
    "print(f\"结算【杀】第一次使用，得分：{score1}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "结算【桃】第一次使用，得分：0\n"
     ]
    }
   ],
   "source": [
    "# 示例2：第二次使用【桃】（正常用法允许1次，但这时已经超出，故尝试技能）\n",
    "card2 = Card(2, \"桃\", \"♣️\", \"7\", \"基本牌\")\n",
    "# 第一次正常使用【桃】\n",
    "score2 = calc.settle(card2, player)\n",
    "print(f\"结算【桃】第一次使用，得分：{score2}\")\n",
    "# # 再次出同样的【桃】，本来额度已满，所以触发技能\n",
    "# card3 = Card(3, \"桃\", \"♣️\", \"7\", \"基本牌\")\n",
    "# score3 = calc.settle(card3, player)\n",
    "# print(f\"结算【桃】第二次使用（技能触发），得分：{score3}\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "发动技能：将原牌 Card(4, 闪, ♥️, 8, 基本牌) 构造成虚拟牌 Card(4, 杀, ♠️, 9, 基本牌)，得分：1\n",
      "结算【闪】使用（技能触发），得分：1\n"
     ]
    }
   ],
   "source": [
    "\n",
    "# 示例3：出一张【闪】牌，本身不能直接用，会尝试技能\n",
    "card4 = Card(4, \"闪\", \"♥️\", \"8\", \"基本牌\")\n",
    "score4 = calc.settle(card4, player)\n",
    "print(f\"结算【闪】使用（技能触发），得分：{score4}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "结算【杀】第二次使用，得分：0\n",
      "结算【杀】第三次使用（技能触发），得分：1\n"
     ]
    }
   ],
   "source": [
    "# 示例4：使用【杀】第三次且未装备诸葛连弩，则触发技能\n",
    "# 这里先出两张【杀】（第一次和第二次用法）\n",
    "card5 = Card(5, \"杀\", \"♠️\", \"9\", \"基本牌\")\n",
    "score5 = calc.settle(card5, player)\n",
    "print(f\"结算【杀】第二次使用，得分：{score5}\")\n",
    "card6 = Card(6, \"杀\", \"♠️\", \"9\", \"基本牌\")\n",
    "score6 = calc.settle(card6, player)\n",
    "print(f\"结算【杀】第三次使用（技能触发），得分：{score6}\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "结算【酒】正常使用且与上一张牌匹配，得分：1\n"
     ]
    }
   ],
   "source": [
    "# 示例5：检验上一张牌与当前牌匹配得分\n",
    "# 假设上一张牌为card6，出一张花色或点数相同的新牌可获得+1分\n",
    "card7 = Card(7, \"酒\", \"♠️\", \"9\", \"基本牌\")  # 与上一张牌点数9相同\n",
    "score7 = calc.settle(card7, player)\n",
    "print(f\"结算【酒】正常使用且与上一张牌匹配，得分：{score7}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "所有排列结果：\n",
      "[1, 2, 3]\n",
      "[1, 3, 2]\n",
      "[2, 1, 3]\n",
      "[2, 3, 1]\n",
      "[3, 2, 1]\n",
      "[3, 1, 2]\n"
     ]
    }
   ],
   "source": [
    "def permute(nums):\n",
    "    \"\"\"\n",
    "    输入一个整型数组，返回该数组的所有排列（全排列）\n",
    "    \"\"\"\n",
    "    res = []  # 存储所有排列结果\n",
    "\n",
    "    def backtrack(start):\n",
    "        # 当start达到数组末尾，说明找到一种排列\n",
    "        if start == len(nums):\n",
    "            res.append(nums.copy())\n",
    "            return\n",
    "        for i in range(start, len(nums)):\n",
    "            # 交换当前元素与i位置元素\n",
    "            nums[start], nums[i] = nums[i], nums[start]\n",
    "            backtrack(start + 1)\n",
    "            # 回溯：恢复交换前的状态\n",
    "            nums[start], nums[i] = nums[i], nums[start]\n",
    "\n",
    "    backtrack(0)\n",
    "    return res\n",
    "\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    input_list = [1, 2, 3]\n",
    "    result = permute(input_list)\n",
    "    print(\"所有排列结果：\")\n",
    "    for perm in result:\n",
    "        print(perm)\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "charlatan",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
